﻿using NodeEditor;

namespace ETHotfix
{
    [NodeEvent(typeof(FloatOperationNode))]
    public class FloatOperationNodeHandle : NodeHandle<FloatOperationNode>
    {
        const string valueStr = "value";
        const string value2Str = "value2";
        const string result = "result";
        protected override void OnHandle(RuntimeTree runtimeTree, RuntimeNode runtimeNode, FloatOperationNode data, Unit unit)
        {
            data.value = runtimeNode.GetInputValue(valueStr, data.value);
            data.value2 = runtimeNode.GetInputValue(value2Str, data.value2);
            switch (data.operationType)
            {
                case OperationType.Add:
                    data.result = data.value + data.value2;
                    break;
                case OperationType.Subtract:
                    data.result = data.value - data.value2;
                    break;
                case OperationType.Multiply:
                    data.result = data.value * data.value2;
                    break;
                case OperationType.Division:
                    data.result = data.value / data.value2;
                    break;
            }
            runtimeNode.SetOutputValue(result, data.result);
        }
    }
}